/*
 * @Descripttion: 
 * @version: 
 * @Author: Eugene
 * @Date: 2024-06-29 17:49:43
 * @LastEditors: Andy
 * @LastEditTime: 2024-07-05 15:25:08
 */
#include "WHW_IRQN.h"
#include "head_task.h"
#include "WHW_Motor.h"
#include "WHW_ROOT.h"
#include "IMU_Task.h"
#include "operate.h"
#include "RUI_CAN.h"

/************************************************************万能分隔符**************************************************************
 * 	@author:			//王涵炜
 *	@performance:	    //定时器回调函数
 *	@parameter:		    //
 *	@time:				//24-04-27 16:55
 *	@ReadMe:			//
 ************************************************************万能分隔符**************************************************************/
uint16_t t = 0;
uint16_t tt = 0;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
    if (htim->Instance == TIM2)
    {   //5ms
//        RUI_F_ROOT();
//        tt++;
//        if (tt > 4)    {tt = 0;  EulerAngle_Target.Pitch++;}
//        if (EulerAngle_Target.Pitch > 180)  {EulerAngle_Target.Pitch = 0;}
    }
    if (htim->Instance == TIM5)
    {   //1ms
        IMU_EKF_Task();

        Angle_Transmit.DataNeaten.q0 = (int16_t)(Q_info_Actual.q0*10000);
        Angle_Transmit.DataNeaten.q1 = (int16_t)(Q_info_Actual.q1*10000);
        Angle_Transmit.DataNeaten.q2 = (int16_t)(Q_info_Actual.q2*10000);
        Angle_Transmit.DataNeaten.q3 = (int16_t)(Q_info_Actual.q3*10000);
        RUI_F_CAN_SEDN_UNION(&hcan1 , 0x202 , Angle_Transmit.Data);
//        Operate_Task();
//        heading(1);
        //0.5s
        t++;
        if(t==500)	{t=0;	LED_TURN;}
    }
}

/************************************************************万能分隔符**************************************************************
 * 	@author:			//小瑞
 *	@performance:	    //CAN接收函数
 *	@parameter:		    //
 *	@time:				//22-11-23 20:42
 *	@ReadMe:			//
 *  @LastUpDataTime:    //2023-04-20 02:52    bestrui
 *  @UpData：           //更新成共用体
 *  @LastUpDataTime:    //2023-05-06 20:23    bestrui
 *  @UpData：           //更新判断逻辑
 ************************************************************万能分隔符**************************************************************/
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
    uint8_t rx_data[8];
    CAN_RxHeaderTypeDef  RxMessage;

    HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxMessage, rx_data);

    if (hcan == &hcan1)
    {
        switch (RxMessage.StdId)
        {
            case 0x201:
            {
//                RUI_F_MOTOR_CAN_RX_2006RM(&WHW_MOTOR_Pitch , rx_data);
                break;
            }

        }
    }

    if (hcan == &hcan2)
    {
        switch (RxMessage.StdId)
        {
            case 0x201:
            {
                RUI_F_MOTOR_CAN_RX_2006RM(&WHW_MOTOR_Roll , rx_data);
                break;
            }
        }
    }

}